import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        accessToken: localStorage.getItem('token'),
        userInfo: JSON.parse(sessionStorage.getItem('userInfo'))
    },
    mutations: {
        //set
        SET_TOKEN:(state, token) => {
            state.token = token;
            localStorage.setItem("token", token);
        },
        SET_USER_INFO:(state, userInfo) => {
            state.userInfo = userInfo;
            sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
        },
        DEL_INFO:(state) => {
            state.token = '';
            state.userInfo = {};
            localStorage.setItem("userInfo", '');
            sessionStorage.setItem("token", JSON.stringify(''));
        }
    },
    getters: {
        //get
        getUserInfo : state => {
            return state.userInfo;
        }
    },
    actions: {},
    modules: {}
})
